﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GoogleAJAXLibrariesAPI
{

    /// <summary>
    /// Put in the masterfile in the head: <SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/>
    /// </summary>
    public class GoogleAjaxApiLoader : Control
    {
        public string ScriptUrl { get; set; }

        public string SslScriptUrl { get; set; }

        protected override void CreateChildControls()
        {
            string url = ScriptUrl;
            if (!string.IsNullOrEmpty(SslScriptUrl) && Page.Request.IsSecureConnection)
            {
                url = SslScriptUrl;
            }

            Literal scriptloader = new Literal();
            Controls.Add(scriptloader);
            scriptloader.Text = string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", url);

            base.CreateChildControls();
        }
    }
}
